package main

import "fmt"

func main() {
	numChan := make(chan int, 10)

	go func() {
		for i := 0; i < 10; i++ {
			numChan <- i
			fmt.Println("write data:", i)
		}
		close(numChan)
	}()

	//读数据
	for {
		v, ok := <-numChan //ok-idiom模式判断
		if !ok {
			fmt.Println("channel is closed!")
			break
		}

		fmt.Println("v: ", v)
	}

	fmt.Println("completed")
}
